package com.witmore.neutron.ai.web.controller;

import com.jk.common.response.ResponseResult;
import com.witmore.neutron.ai.web.controller.vo.ApiChatCompletionRequest;
import com.witmore.neutron.ai.web.service.ApiAgentService;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 豆子高
 * @date 2025-05-26 14:13
 */
@RestController
@RequestMapping("v1/api/chat/")
public class ApiAgentController {


    @Autowired
    private ApiAgentService apiAgentService;

    /**
     * 文本对话
     */
    @PostMapping("completions")
    public ResponseResult<String> chatNew(@RequestParam("code") String agentCode, HttpServletRequest request,
                                          @RequestBody ApiChatCompletionRequest req) {
        if (StringUtils.isEmpty(agentCode)) {
            return ResponseResult.fail(1001, "请求参数异常");
        }
        if (req == null || req.getMessages() == null || req.getMessages().isEmpty()) {
            return ResponseResult.fail(1001, "请求参数异常");
        }
        req.setStream(false);
        req.setSource("api");
        req.setAgentCode(agentCode);
        return apiAgentService.chatNew(request, req);
    }
}
